<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>数据库配置</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<link rel="stylesheet" href="layui/css/layui.css">
	</head>
	<body>

		<div class="layui-layout layui-layout-admin">
		<div class="layui-body">

			<form class="layui-form" action="">
				<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
					<legend>增加数据源配置</legend>
				</fieldset>
				<div class="layui-form-item">
					<label class="layui-form-label">地址</label>
					<div class="layui-input-inline">
						<input type="text" name="url" lay-verify="required" autocomplete="on" placeholder="请输入URL"
							class="layui-input">
					</div>
				</div>
			
				<div class="layui-form-item">
					<label class="layui-form-label">用户名</label>
					<div class="layui-input-inline">
						<input type="text" name="userName" lay-verify="required" autocomplete="on" placeholder="请输入用户名"
							class="layui-input">
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">密码</label>
					<div class="layui-input-inline">
						<input type="text" name="password" lay-verify="required" autocomplete="on" placeholder="请输入密码"
							class="layui-input">
					</div>
				</div>
				
				<div class="layui-form-item">
					<label class="layui-form-label">驱动类</label>
					<div class="layui-input-inline">
						<input type="text" name="driverClassName" lay-verify="required" autocomplete="on" placeholder="请输入driverClassName"
							class="layui-input">
					</div>
				</div>
				
				<div class="layui-form-item">
					<div class="layui-input-block">
						<button type="submit" class="layui-btn" lay-submit="" lay-filter="db">立即提交</button>
						<button type="reset" class="layui-btn layui-btn-primary">重置</button>
					</div>
				</div>
			</form>
		</div>
		</div>
		<script src="layui/layui.js" charset="utf-8"></script>
		<script>
			layui.config({
			        base: 'js/', //静态资源所在路径
			    }).extend({
			        index: 'http', //主入口模块
			    }).use(['form', 'layedit', 'jquery', 'element', 'http'], function() {
				var form = layui.form,
					layer = layui.layer,
					layedit = layui.layedit,
					api = layui.http.api,
					element = layui.element;
				$ = layui.jquery;
				var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
				form.on('submit(db)', function(data) {
					$.ajax({
						type: 'POST',
						url: api + 'db/save',
						data: {
							'data': JSON.stringify(data.field)
						},
						dataType: 'json',

						success: function(result) {
							if (result.code == 0) {
								parent.layer.close(index);
							}else{
								layer.msg('保存失败');
							}
						},
						error: function(result) {
							layer.alert(result, {
								title: '文件数据处理出现异常'
							})
						}
					})
					return false;
				})

			})
		</script>
	</body>
</html>
